/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.parameter_constraints;

import picounit.features.mocking.MethodUtil;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public abstract class EqualsInvocationHandler implements InvocationHandler {
	private final MethodUtil methodUtil = new MethodUtil();

	public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		if (methodUtil.isEquals(method)) {
			return new Boolean(args[0] != null && isEqual(args[0]));
		}
		else if (methodUtil.isHashCode(method)) {
			return new Integer(getClass().hashCode());
		}
		else if (methodUtil.isToString(method)) {
			return toString();
		}

		return null;
	}
	
	public abstract boolean isEqual(Object object);

	@Override
	public abstract String toString();
}